module.exports=function push(){
    'use strict';
var GeTui = require('../../node_modules/gt-push-sdk/GT.push');
var Target = require('../../node_modules/gt-push-sdk/getui/Target');
var SingleMessage = require('../../node_modules/gt-push-sdk/getui/message/SingleMessage');
var TransmissionTemplate = require('../../node_modules/gt-push-sdk/getui/template/TransmissionTemplate');
var NotificationTemplate = require('../../node_modules/gt-push-sdk/getui/template/NotificationTemplate');
//采用"NodeJs SDK 快速入门"， "第二步 获取访问凭证 "中获得的应用配置，用户可以自行替换
var APPID = 'CA67c9kugl97regiaEA3Q5';
var APPKEY = 'qEvPkjgbiA9nINUSqcLb61';
var MASTERSECRET = 'AHtOaveDOxA823xpQF5Ts1';
var CID = '4c08e32df8c29a6c34df4da45ee7474c';
//别名推送方式
//var ALIAS = '';
var HOST = 'http://sdk.open.api.igexin.com/apiex.htm';

var gt = new GeTui(HOST, APPKEY, MASTERSECRET);

gt.connect(function () {
    pushMessageToSingle();
});
function pushMessageToSingle() {
    var template = TransmissionTemplateDemo();
    //单推消息体
    var message = new SingleMessage({
        isOffline: true,                        //是否离线
        offlineExpireTime: 3600 * 12 * 1000,    //离线时间
        data: template                          //设置推送消息类型
    });
    //接收方
    var target = new Target({
        appId: APPID,
        clientId: CID
        //alias:ALIAS
    });

    target.setAppId(APPID).setClientId(CID);
    gt.pushMessageToSingle(message, target, function(err, res){
        console.log(res)
        if(err != null && err.exception != null && err.exception instanceof  RequestError){
            var requestId = err.exception.requestId;
            console.log(err.exception.requestId);
            //发送异常重传
            gt.pushMessageToSingle(message,target,requestId,function(err, res){
                console.log(err);
                console.log(res);
            });
        }
    });
}
function TransmissionTemplateDemo() {
    var template = new NotificationTemplate({
        appId: APPID,
        appKey: APPKEY,
        title: '测试todo2',
        text: '测试透传',
        logoUrl: 'http://wwww.igetui.com/logo.png',
        isRing: true,
        isVibrate: true,
        isClearable: false,
        transmissionType: 1,
        transmissionContent: 'user/uni-feedback/uni-feedback'
    });
    return template;
}
}

